/**
 * Created by gongxun on 17/2/20.
 */

var KwxSecondBase = KwxBaseLayer.extend({
    mContentNode : null,
    Panel_buttom : null,
    ctor : function () {
        this._super();
    },

    loadSecondCCS : function(file){
        this.loadCocostudio("res/ccs/KwxSecondBase.json");
        this.Panel_buttom = mo.seekWidgetByName(this.ccsNode, "Panel_buttom");

        //content layer
        var json = ccs.load(file);
        this.mContentNode = json.node;
        this.Panel_buttom.addChild(this.mContentNode);
        this.resetSize(this.mContentNode);

        //修复字体
        mo.gameHelper.fixIosText(this.ccsNode);

        //关闭
        mo.seekWidgetByName(this.ccsNode, "Button_return").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEndMenuClose(type)) {
                this.onSecondClose();
            }
        }, this);
    },

    setTitleText : function(text){
        mo.gameHelper.loadTextureImage(mo.seekWidgetByName(this.ccsNode, "Image_title_logo"), text);
    },

    onEnter : function(){
        this._super();
        this.onSecondShow();
    },

    onSecondShow : function(){

        // var time = 0.2;
        //
        // var panelTopToY = mo.gameHelper.projectCode == 2 ? 0 : mo.gameSize.y - 80;
        // this.Panel_top.setOpacity(0);
        // this.Panel_top.setPositionY(mo.gameSize.y);
        // this.Panel_top.runAction(cc.spawn(
        //     cc.sequence(cc.fadeIn(time)),
        //     cc.sequence(cc.moveTo(time, cc.p(0, panelTopToY)))
        // ));
        //
        // this.Panel_buttom.setOpacity(0);
        // this.Panel_buttom.setPositionY(-mo.gameSize.y);
        // this.Panel_buttom.runAction(cc.spawn(
        //     cc.sequence(cc.fadeIn(time)),
        //     cc.sequence(cc.moveTo(time, cc.p(0, 0)))
        // ));
    },

    onSecondClose : function(){
        this.removeFromParent();
        // var isClose = false;
        //
        // //拦截
        // var currenttime = mo.gameHelper.getMillisecond();
        // if (currenttime - this.mTimestamp < 500){
        //     isClose = false;
        // }else{
        //     this.mTimestamp = currenttime;
        //
        //     var time = 0.2;
        //
        //     this.Panel_top.stopAllActions();
        //     this.Panel_top.runAction(cc.spawn(
        //         cc.sequence(cc.fadeOut(time)),
        //         cc.sequence(cc.moveTo(time, cc.p(0, mo.gameSize.y)))
        //     ));
        //
        //     var that = this;
        //     this.Panel_buttom.stopAllActions();
        //     this.Panel_buttom.runAction(cc.spawn(
        //         cc.sequence(cc.fadeIn(time / 2)),
        //         cc.sequence(
        //             cc.moveTo(time, cc.p(0, -mo.gameSize.y)),
        //             cc.callFunc(function(){
        //                 that.removeFromParent();
        //             })
        //         )
        //     ));
        //
        //     isClose = true;
        // }
        //
        // return isClose;
    },

    setBtnBackFunc : function(func, obj){
        mo.seekWidgetByName(this.ccsNode, "Button_back").setVisible(true);
        mo.seekWidgetByName(this.ccsNode, "Button_back").addTouchEventListener(function(sender, type){
            if (mo.gameHelper.getIsTouchEnd(type)) {
                func.call(obj);
            }
        }, this);
    }
});